1 using System;
2 using System.Collections.Generic;
3 using System.ComponentModel;
4 using System.Data;
5 using System.Drawing;
6 using System.Linq;
7 using System.Text;
8 using System.Windows.Forms;
9 using System.Data.SqlClient;
10 using System.Security.Cryptography;
11 using CrystalDecisions.Shared;
12 using CrystalDecisions.CrystalReports.Engine;
13 namespace WarehouseManagementSystem
14 {
15 public partial class frmOrder : Form
16 {
17 SqlCommand cmd;
18 SqlConnection con;
19 SqlDataReader rdr;
20 ConnectionString cs = new ConnectionString();
21
22 public frmOrder()
23 {
24 InitializeComponent();
25 }
26 private void auto()
27 {
28 txtInvoiceNo.Text = "INV-" + GetUniqueKey(8);
29
30 }
31 public static string GetUniqueKey(int maxSize)
32 {
33 char[] chars = new char[62];
34 chars = "123456789".ToCharArray();
35 byte[] data = new byte[1];
36 RNGCryptoServiceProvider crypto = new RNGCryptoServiceProvider();
37 crypto.GetNonZeroBytes(data);
38 data = new byte[maxSize];
39 crypto.GetNonZeroBytes(data);
40 StringBuilder result = new StringBuilder(maxSize);
41 foreach (byte b in data)
42 {
43 result.Append(chars[b % (chars.Length)]);
44 }
45 return result.ToString();
46 }
47
48 private void Save_Click(object sender, EventArgs e)
49 {
50 try
51 {
52 if (txtCustomerID.Text == "")
53 {
54 MessageBox.Show("Please retrieve Customer Details", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
55 Button1.Focus();
56 return;
57 }
58
59 if (txtTaxPer.Text == "")
60 {
61 MessageBox.Show("Please enter tax percentage", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
62 txtTaxPer.Focus();
63 return;
64 }
65 if (txtDiscountPer.Text == "")
66 {
67 MessageBox.Show("Please enter discount percentage", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
68 txtDiscountPer.Focus();
69 return;
70 }
71 if (txtTotalPayment.Text == "")
72 {
73 MessageBox.Show("Please enter total payment", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
74 txtTotalPayment.Focus();
75 return;
76 }
77 if (cmbPaymentType.Text == "")
78 {
79 MessageBox.Show("Please select payment type", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
80 cmbPaymentType.Focus();
81 return;
82 }
83 if (cmbStatus.Text == "")
84 {
85 MessageBox.Show("Please select status", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
86 cmbStatus.Focus();
87 return;
88 }
89 if (ListView1.Items.Count == 0)
90 {
91 MessageBox.Show("sorry no product added", "", MessageBoxButtons.OK, MessageBoxIcon.Warning);
92 return;
93 }
94
95 auto();
96
97 con = new SqlConnection(cs.DBConn);
98 con.Open();
99
100 string cb = "insert Into Invoice_Info(InvoiceNo,InvoiceDate,CustomerID,SubTotal,VATPer,VATAmount,DiscountPer,DiscountAmount,GrandTotal,TotalPayment,PaymentDue,PaymentType,Status,Remarks) VALUES ('" + txtInvoiceNo.Text + "','" + dtpInvoiceDate.Text + "','" + txtCustomerID.Text + "'," + txtSubTotal.Text + "," + txtTaxPer.Text + "," + txtTaxAmt.Text + ","+ txtDiscountPer.Text +","+ txtDiscountAmount.Text +"," + txtTotal.Text + "," + txtTotalPayment.Text + "," + txtPaymentDue.Text + ",'" + cmbPaymentType.Text + "','"+ cmbStatus.Text + "','" + txtRemarks.Text + "')";
101 cmd = new SqlCommand(cb);
102 cmd.Connection = con;
103 cmd.ExecuteReader();
104 if (con.State == ConnectionState.Open)
105 {
106 con.Close();
107 }
108 con.Close();
109
110
111 for (int i = 0; i <= ListView1.Items.Count - 1; i++)
112 {
113 con = new SqlConnection(cs.DBConn);
114
115 string cd = "insert Into ProductSold(InvoiceNo,ProductID,ProductName,Quantity,Price,TotalAmount) VALUES (@d1,@d2,@d3,@d4,@d5,@d6)";
116 cmd = new SqlCommand(cd);
117 cmd.Connection = con;
118 cmd.Parameters.AddWithValue("d1", txtInvoiceNo.Text);
119 cmd.Parameters.AddWithValue("d2", ListView1.Items[i].SubItems[1].Text);
120 cmd.Parameters.AddWithValue("d3", ListView1.Items[i].SubItems[2].Text);
121 cmd.Parameters.AddWithValue("d4", ListView1.Items[i].SubItems[4].Text);
122 cmd.Parameters.AddWithValue("d5", ListView1.Items[i].SubItems[3].Text);
123 cmd.Parameters.AddWithValue("d6", ListView1.Items[i].SubItems[5].Text);
124 con.Open();
125 cmd.ExecuteNonQuery();
126 con.Close();
127 }
128 for (int i = 0; i <= ListView1.Items.Count - 1; i++)
129 {
130 con = new SqlConnection(cs.DBConn);
131 con.Open();
132 string cb1 = "update temp_stock set Quantity = Quantity - " + ListView1.Items[i].SubItems[4].Text + " where ProductID= '" + ListView1.Items[i].SubItems[1].Text + "'";
133 cmd = new SqlCommand(cb1);
134 cmd.Connection = con;
135 cmd.ExecuteNonQuery();
136 con.Close();
137 }
138
139 Save.Enabled = false;
140 btnPrint.Enabled = true;
141 GetData();
142 MessageBox.Show("Successfully Placed", "Order", MessageBoxButtons.OK, MessageBoxIcon.Information);
143 }
144 catch (Exception ex)
145 {
146 MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
147 }
148 }
149
150 private void frmInvoice_Load(object sender, EventArgs e)
151 {
152 GetData();
153 }
154
155 private void Button1_Click(object sender, EventArgs e)
156 {
157 this.Hide();
158 frmCustomersRecord1 frm = new frmCustomersRecord1();
159 frm.lblUser.Text = label6.Text;
160 frm.Visible=true;
161 }
162
163 public void Calculate()
164 {
165 if (txtTaxPer.Text != "")
166 {
167 txtTaxAmt.Text = Convert.ToInt32((Convert.ToInt32(txtSubTotal.Text) * Convert.ToDouble(txtTaxPer.Text) / 100)).ToString();
168
169 }
170 if (txtDiscountPer.Text != "")
171 {
172 txtDiscountAmount.Text = Convert.ToInt32(((Convert.ToInt32(txtSubTotal.Text) + Convert.ToInt32(txtTaxAmt.Text)) * Convert.ToDouble(txtDiscountPer.Text) / 100)).ToString();
173 }
174 int val1 = 0;
175 int val2 = 0;
176 int val3 = 0;
177 int val4 = 0;
178 int val5= 0;
179 int.TryParse(txtTaxAmt.Text, out val1);
180 int.TryParse(txtSubTotal.Text, out val2);
181 int.TryParse(txtDiscountAmount.Text, out val3);
182 int.TryParse(txtTotal.Text, out val4);
183 int.TryParse(txtTotalPayment.Text, out val5);
184 val4 = val1 + val2 - val3;
185 txtTotal.Text = val4.ToString();
186 int I = (val4 - val5);
187 txtPaymentDue.Text = I.ToString();
188
189
190 }
191 private void txtSaleQty_TextChanged(object sender, EventArgs e)
192 {
193 int val1 = 0;
194 int val2 = 0;
195 int.TryParse(txtPrice.Text, out val1);
196 int.TryParse(txtSaleQty.Text, out val2);
197 int I = (val1 * val2);
198 txtTotalAmount.Text = I.ToString();
199 }
200
201 public double subtot()
202 {
203 int i = 0;
204 int j = 0;
205 int k = 0;
206 i = 0;
207 j = 0;
208 k = 0;
209
210
211 try
212 {
213
214 j = ListView1.Items.Count;
215 for (i = 0; i <= j - 1; i++)
216 {
217 k = k + Convert.ToInt32(ListView1.Items[i].SubItems[5].Text);
218 }
219
220 }
221
222 catch (Exception ex)
223 {
224 MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
225 }
226 return k;
227
228 }
229
230 private void Button7_Click(object sender, EventArgs e)
231 {
232 try
233 {
234 if (txtCustomerID.Text == "")
235 {
236 MessageBox.Show("Please retrieve Customer ID", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
237 txtCustomerID.Focus();
238 return;
239 }
240
241 if (txtProductName.Text=="")
242 {
243 MessageBox.Show("Please retrieve product name", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
244 return;
245 }
246 if (txtSaleQty.Text=="")
247 {
248 MessageBox.Show("Please enter no. of sale quantity", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
249 txtSaleQty.Focus();
250 return;
251 }
252 int SaleQty = Convert.ToInt32(txtSaleQty.Text);
253 if (SaleQty == 0)
254 {
255 MessageBox.Show("no. of sale quantity can not be zero", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
256 txtSaleQty.Focus();
257 return;
258 }
259
260 if (ListView1.Items.Count==0)
261 {
262
263 ListViewItem lst = new ListViewItem();
264 lst.SubItems.Add(txtProductID.Text);
265 lst.SubItems.Add(txtProductName.Text);
266 lst.SubItems.Add(txtPrice.Text);
267 lst.SubItems.Add(txtSaleQty.Text);
268 lst.SubItems.Add(txtTotalAmount.Text);
269 ListView1.Items.Add(lst);
270 txtSubTotal.Text = subtot().ToString();
271
272 Calculate();
273 txtProductName.Text = "";
274 txtProductID.Text = "";
275 txtPrice.Text = "";
276 txtAvailableQty.Text = "";
277 txtSaleQty.Text = "";
278 txtTotalAmount.Text = "";
279 txtProduct.Text = "";
280 return;
281 }
282
283 for (int j = 0; j <= ListView1.Items.Count - 1; j++)
284 {
285 if (ListView1.Items[j].SubItems[1].Text == txtProductID.Text)
286 {
287 ListView1.Items[j].SubItems[1].Text = txtProductID.Text;
288 ListView1.Items[j].SubItems[2].Text = txtProductName.Text;
289 ListView1.Items[j].SubItems[3].Text = txtPrice.Text;
290 ListView1.Items[j].SubItems[4].Text = (Convert.ToInt32(ListView1.Items[j].SubItems[4].Text) + Convert.ToInt32(txtSaleQty.Text)).ToString();
291 ListView1.Items[j].SubItems[5].Text = (Convert.ToInt32(ListView1.Items[j].SubItems[5].Text) + Convert.ToInt32(txtTotalAmount.Text)).ToString();
292 txtSubTotal.Text = subtot().ToString();
293 Calculate();
294 txtProductName.Text = "";
295 txtProductID.Text = "";
296 txtPrice.Text = "";
297 txtAvailableQty.Text = "";
298 txtSaleQty.Text = "";
299 txtTotalAmount.Text = "";
300 return;
301
302 }
303 }
304
305 ListViewItem lst1 = new ListViewItem();
306
307 lst1.SubItems.Add(txtProductID.Text);
308 lst1.SubItems.Add(txtProductName.Text);
309 lst1.SubItems.Add(txtPrice.Text);
310 lst1.SubItems.Add(txtSaleQty.Text);
311 lst1.SubItems.Add(txtTotalAmount.Text);
312 ListView1.Items.Add(lst1);
313 txtSubTotal.Text = subtot().ToString();
314 Calculate();
315 txtProductName.Text = "";
316 txtProductID.Text = "";
317 txtPrice.Text = "";
318 txtAvailableQty.Text = "";
319 txtSaleQty.Text = "";
320 txtTotalAmount.Text = "";
321 return;
322 }
323 catch (Exception ex)
324 {
325 MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
326 }
327 }
328
329 private void btnRemove_Click(object sender, EventArgs e)
330 {
331 try
332 {
333 if (ListView1.Items.Count == 0)
334 {
335 MessageBox.Show("No items to remove", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
336 }
337 else
338 {
339 int itmCnt = 0;
340 int i = 0;
341 int t = 0;
342
343 ListView1.FocusedItem.Remove();
344 itmCnt = ListView1.Items.Count;
345 t = 1;
346
347 for (i = 1; i <= itmCnt + 1; i++)
348 {
349 //Dim lst1 As New ListViewItem(i)
350 //ListView1.Items(i).SubItems(0).Text = t
351 t = t + 1;
352
353 }
354 txtSubTotal.Text = subtot().ToString();
355 Calculate();
356 }
357
358 btnRemove.Enabled = false;
359 if (ListView1.Items.Count == 0)
360 {
361 txtSubTotal.Text = "";
362 }
363 }
364 catch (Exception ex)
365 {
366 MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
367 }
368 }
369
370 private void txtTaxPer_TextChanged(object sender, EventArgs e)
371 {
372 try
373 {
374 if (string.IsNullOrEmpty(txtTaxPer.Text))
375 {
376 txtTaxAmt.Text = "";
377 txtTotal.Text = "";
378 return;
379 }
380 Calculate();
381 }
382 catch (Exception ex)
383 {
384 MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
385 }
386 }
387
388 private void ListView1_SelectedIndexChanged(object sender, EventArgs e)
389 {
390 btnRemove.Enabled = true;
391 }
392
393 private void textBox1_TextChanged(object sender, EventArgs e)
394 {
395 try
396 {
397 con = new SqlConnection(cs.DBConn);
398 con.Open();
399 String sql = "SELECT Product.ProductID,ProductName,Features,Price,sum(Quantity) from Temp_Stock,Product where Temp_Stock.ProductID=Product.ProductID and ProductName like '" + txtProduct.Text + "%' group by product.ProductID,productname,Price,Features,Quantity having(quantity>0) order by ProductName";
400 cmd = new SqlCommand(sql, con);
401 rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
402 dataGridView1.Rows.Clear();
403 while (rdr.Read() == true)
404 {
405 dataGridView1.Rows.Add(rdr[0], rdr[1], rdr[2], rdr[3], rdr[4]);
406 }
407 con.Close();
408 }
409 catch (Exception ex)
410 {
411 MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
412 }
413 }
414
415 private void dataGridView1_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
416 {
417 string strRowNumber = (e.RowIndex + 1).ToString();
418 SizeF size = e.Graphics.MeasureString(strRowNumber, this.Font);
419 if (dataGridView1.RowHeadersWidth < Convert.ToInt32((size.Width + 20)))
420 {
421 dataGridView1.RowHeadersWidth = Convert.ToInt32((size.Width + 20));
422 }
423 Brush b = SystemBrushes.ControlText;
424 e.Graphics.DrawString(strRowNumber, this.Font, b, e.RowBounds.Location.X + 15, e.RowBounds.Location.Y + ((e.RowBounds.Height - size.Height) / 2));
425
426 }
427
428 private void dataGridView1_RowHeaderMouseClick(object sender, DataGridViewCellMouseEventArgs e)
429 {
430 try
431 {
432 DataGridViewRow dr = dataGridView1.SelectedRows[0];
433 txtProductID.Text = dr.Cells[0].Value.ToString();
434 txtProductName.Text = dr.Cells[1].Value.ToString();
435 txtPrice.Text = dr.Cells[3].Value.ToString();
436 txtAvailableQty.Text = dr.Cells[4].Value.ToString();
437 txtSaleQty.Focus();
438 }
439 catch (Exception ex)
440 {
441 MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
442 }
443 }
444 public void GetData()
445 {
446 try
447 {
448 con = new SqlConnection(cs.DBConn);
449 con.Open();
450 String sql = "SELECT Product.ProductID,ProductName,Features,Price,sum(Quantity) from Temp_Stock,Product where Temp_Stock.ProductID=Product.ProductID group by Product.productID,productname,Price,Features,Quantity having(Quantity>0) order by ProductName";
451 cmd = new SqlCommand(sql, con);
452 rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
453 dataGridView1.Rows.Clear();
454 while (rdr.Read() == true)
455 {
456 dataGridView1.Rows.Add(rdr[0], rdr[1], rdr[2], rdr[3],rdr[4]);
457 }
458 con.Close();
459 }
460 catch (Exception ex)
461 {
462 MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
463 }
464 }
465 private void Reset()
466 {
467 txtInvoiceNo.Text = "";
468 cmbStatus.Text = "";
469 cmbPaymentType.Text = "";
470 dtpInvoiceDate.Text = DateTime.Today.ToString();
471 txtCustomerID.Text = "";
472 txtCustomerName.Text = "";
473 txtProductName.Text = "";
474 txtProductID.Text = "";
475 txtPrice.Text = "";
476 txtAvailableQty.Text = "";
477 txtSaleQty.Text = "";
478 txtTotalAmount.Text = "";
479 ListView1.Items.Clear();
480 txtDiscountAmount.Text = "";
481 txtDiscountPer.Text = "";
482
483 txtSubTotal.Text = "";
484 txtTaxPer.Text = "";
485 txtTaxAmt.Text = "";
486 txtTotal.Text = "";
487 txtTotalPayment.Text = "";
488 txtPaymentDue.Text = "";
489 txtProduct.Text = "";
490 txtRemarks.Text = "";
491 Save.Enabled = true;
492 Delete.Enabled = false;
493 btnUpdate.Enabled = false;
494 btnRemove.Enabled = false;
495 btnPrint.Enabled = false;
496 ListView1.Enabled = true;
497 Button7.Enabled = true;
498
499 }
500
501 private void NewRecord_Click(object sender, EventArgs e)
502 {
503 Reset();
504 Reset();
505 }
506
507 private void Delete_Click(object sender, EventArgs e)
508 {
509 if (MessageBox.Show("Do you really want to delete this record?", "Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.Yes)
510 {
511 delete_records();
512 }
513 }
514 private void delete_records()
515 {
516
517 try
518 {
519
520 int RowsAffected = 0;
521 con = new SqlConnection(cs.DBConn);
522 con.Open();
523 string cq1 = "delete from productSold where InvoiceNo='" + txtInvoiceNo.Text + "'";
524 cmd = new SqlCommand(cq1);
525 cmd.Connection = con;
526 RowsAffected = cmd.ExecuteNonQuery();
527 con.Close();
528 con = new SqlConnection(cs.DBConn);
529 con.Open();
530 string cq = "delete from Invoice_Info where InvoiceNo='" + txtInvoiceNo.Text + "'";
531 cmd = new SqlCommand(cq);
532 cmd.Connection = con;
533 RowsAffected = cmd.ExecuteNonQuery();
534 if (RowsAffected > 0)
535 {
536 MessageBox.Show("Successfully deleted", "Record", MessageBoxButtons.OK, MessageBoxIcon.Information);
537 Reset();
538 }
539 else
540 {
541 MessageBox.Show("No Record found", "Sorry", MessageBoxButtons.OK, MessageBoxIcon.Information);
542 Reset();
543 }
544 if (con.State == ConnectionState.Open)
545 {
546 con.Close();
547 }
548
549
550 }
551 catch (Exception ex)
552 {
553 MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
554 }
555 }
556
557 private void frmInvoice_FormClosing(object sender, FormClosingEventArgs e)
558 {
559 this.Hide();
560 frmMainMenu frm = new frmMainMenu();
561 frm.lblUser.Text = label6.Text;
562 frm.Show();
563 }
564
565 private void txtTotalPayment_TextChanged(object sender, EventArgs e)
566 {
567 int val1 = 0;
568 int val2 = 0;
569 int.TryParse(txtTotal.Text, out val1);
570 int.TryParse(txtTotalPayment.Text, out val2);
571 int I = (val1 - val2);
572 txtPaymentDue.Text = I.ToString();
573 }
574
575 private void txtTotalPayment_Validating(object sender, CancelEventArgs e)
576 {
577 int val1 = 0;
578 int val2 = 0;
579 int.TryParse(txtTotal.Text, out val1);
580 int.TryParse(txtTotalPayment.Text, out val2);
581 if (val2 > val1)
582 {
583 MessageBox.Show("Total Payment can't be more than grand total", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
584 txtTotalPayment.Text = "";
585 txtPaymentDue.Text = "";
586 txtTotalPayment.Focus();
587 return;
588 }
589 }
590
591 private void txtSaleQty_Validating(object sender, CancelEventArgs e)
592 {
593
594 int val1 = 0;
595 int val2 = 0;
596 int.TryParse(txtAvailableQty.Text, out val1);
597 int.TryParse(txtSaleQty.Text, out val2);
598 if (val2 > val1)
599 {
600 MessageBox.Show("Selling quantities are more than available quantities", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
601 txtSaleQty.Text = "";
602 txtTotalAmount.Text = "";
603 txtSaleQty.Focus();
604 return;
605 }
606 }
607
608 private void btnPrint_Click(object sender, EventArgs e)
609 {
610 try
611 {
612 Cursor = Cursors.WaitCursor;
613 timer1.Enabled = true;
614 rptInvoice rpt = new rptInvoice();
615 //The report you created.
616 cmd = new SqlCommand();
617 SqlDataAdapter myDA = new SqlDataAdapter();
618 POS_DBDataSet myDS = new POS_DBDataSet();
619 //The DataSet you created.
620 con = new SqlConnection(cs.DBConn);
621 cmd.Connection = con;
622 cmd.CommandText = "SELECT * from product,invoice_info,productsold,customer where invoice_info.invoiceno=productsold.invoiceno and invoice_info.customerID=Customer.CustomerID and ProductSold.ProductID=Product.ProductID and Invoice_info.invoiceNo='" + txtInvoiceNo.Text + "'";
623 cmd.CommandType = CommandType.Text;
624 myDA.SelectCommand = cmd;
625 myDA.Fill(myDS, "product");
626 myDA.Fill(myDS, "Invoice_Info");
627 myDA.Fill(myDS, "ProductSold");
628 myDA.Fill(myDS, "Customer");
629 rpt.SetDataSource(myDS);
630 frmInvoiceReport frm = new frmInvoiceReport();
631 frm.crystalReportViewer1.ReportSource = rpt;
632 frm.Visible=true;
633 }
634 catch (Exception ex)
635 {
636 MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
637 }
638 }
639
640 private void timer1_Tick(object sender, EventArgs e)
641 {
642 Cursor = Cursors.Default;
643 timer1.Enabled = false;
644 }
645
646 private void btnUpdate_Click(object sender, EventArgs e)
647 {
648 try
649 {
650 con = new SqlConnection(cs.DBConn);
651 con.Open();
652 String cb = "update Invoice_info set CustomerID='" + txtCustomerID.Text + "', VATPer="+ txtTaxPer.Text +",VATAmount=" + txtTaxAmt.Text +",DiscountPer="+ txtDiscountPer.Text +",DiscountAmount="+ txtDiscountAmount.Text +",GrandTotal= " + txtTotal.Text + ",TotalPayment= " + txtTotalPayment.Text + ",PaymentDue= " + txtPaymentDue.Text + ",Remarks='" + txtRemarks.Text + "',Status='" + cmbStatus.Text + "',PaymentType='" + cmbPaymentType.Text + "' where Invoiceno= '" + txtInvoiceNo.Text + "'";
653 cmd = new SqlCommand(cb);
654 cmd.Connection = con;
655 cmd.ExecuteReader();
656 con.Close();
657
658 GetData();
659 btnUpdate.Enabled = false;
660 MessageBox.Show("Successfully updated", "Record", MessageBoxButtons.OK, MessageBoxIcon.Information);
661 }
662 catch (Exception ex)
663 {
664 MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
665 }
666 }
667
668 private void Button4_Click(object sender, EventArgs e)
669 {
670 this.Hide();
671 frmSalesRecord1 frm = new frmSalesRecord1();
672 frm.DataGridView1.DataSource = null;
673 frm.dtpInvoiceDateFrom.Text = DateTime.Today.ToString();
674 frm.dtpInvoiceDateTo.Text = DateTime.Today.ToString();
675 frm.GroupBox3.Visible = false;
676 frm.DataGridView3.DataSource = null;
677 frm.cmbCustomerName.Text = "";
678 frm.GroupBox4.Visible = false;
679 frm.DateTimePicker1.Text = DateTime.Today.ToString();
680 frm.DateTimePicker2.Text = DateTime.Today.ToString();
681 frm.DataGridView2.DataSource = null;
682 frm.GroupBox10.Visible = false;
683 frm.FillCombo();
684 frm.lblUser.Text = label6.Text;
685 frm.Show();
686 }
687
688 private void txtSaleQty_KeyPress(object sender, KeyPressEventArgs e)
689 {
690 if (char.IsDigit(e.KeyChar) || char.IsControl(e.KeyChar))
691 {
692 e.Handled = false;
693 }
694 else
695 {
696 e.Handled = true;
697 }
698 }
699
700 private void txtTotalPayment_KeyPress(object sender, KeyPressEventArgs e)
701 {
702 if (char.IsDigit(e.KeyChar) || char.IsControl(e.KeyChar))
703 {
704 e.Handled = false;
705 }
706 else
707 {
708 e.Handled = true;
709 }
710 }
711
712 private void txtTaxPer_KeyPress(object sender, KeyPressEventArgs e)
713 {
714 // allows 0-9, backspace, and decimal
715 if (((e.KeyChar < 48 || e.KeyChar > 57) && e.KeyChar != 8 && e.KeyChar != 46))
716 {
717 e.Handled = true;
718 return;
719 }
720 }
721
722 private void txtDiscountPer_TextChanged(object sender, EventArgs e)
723 {
724 Calculate();
725 }
726 }
727 }